{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2024-02-26T12:30:16.920680Z",
     "start_time": "2024-02-26T12:30:16.483867600Z"
    }
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import pickle\n",
    "from datetime import datetime"
   ]
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "dtrader_1=np.load('alphastock/code/RL/ccso_result/2023_01_01-2023_03_31.npy')\n",
    "dtrader_1=pd.DataFrame(dtrader_1)\n",
    "dtrader_1.columns=['daily_return']\n",
    "dtrader_return_1=dtrader_1/dtrader_1.shift(1)\n",
    "dtrader_return_1.fillna(1,inplace=True)\n",
    "\n",
    "dtrader_2=np.load('alphastock/code/RL/ccso_result/2023_04_01-2023_06_30.npy')\n",
    "dtrader_2=pd.DataFrame(dtrader_2)\n",
    "dtrader_2.columns=['daily_return']\n",
    "dtrader_return_2=dtrader_2/dtrader_2.shift(1)\n",
    "dtrader_return_2.fillna(1,inplace=True)\n",
    "\n",
    "dtrader_3=np.load('alphastock/code/RL/ccso_result/2023_07_01-2023_09_30.npy')\n",
    "dtrader_3=pd.DataFrame(dtrader_3)\n",
    "dtrader_3.columns=['daily_return']\n",
    "dtrader_return_3=dtrader_3/dtrader_3.shift(1)\n",
    "dtrader_return_3.fillna(1,inplace=True)\n",
    "\n",
    "dtrader_4=np.load('alphastock/code/RL/ccso_result/2023_10_01-2023_12_31.npy')\n",
    "dtrader_4=pd.DataFrame(dtrader_4)\n",
    "dtrader_4.columns=['daily_return']\n",
    "dtrader_return_4=dtrader_4/dtrader_4.shift(1)\n",
    "dtrader_return_4.fillna(1,inplace=True)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-26T12:30:16.942088300Z",
     "start_time": "2024-02-26T12:30:16.926912100Z"
    }
   },
   "id": "ae1292b6b64a8cc0",
   "execution_count": 2
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "dtrader_return = pd.concat([dtrader_return_1, dtrader_return_2, dtrader_return_3, dtrader_return_4])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-26T12:30:16.955383Z",
     "start_time": "2024-02-26T12:30:16.937469800Z"
    }
   },
   "id": "76403ba959134cba",
   "execution_count": 3
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "data": {
      "text/plain": "    daily_return\n0       1.000000\n1       1.000000\n2       1.013637\n3       0.997379\n4       0.999823\n..           ...\n55      1.002194\n56      0.997849\n57      1.008913\n58      1.017788\n59      1.004746\n\n[242 rows x 1 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>daily_return</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1.000000</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>1.000000</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>1.013637</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>0.997379</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>0.999823</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>55</th>\n      <td>1.002194</td>\n    </tr>\n    <tr>\n      <th>56</th>\n      <td>0.997849</td>\n    </tr>\n    <tr>\n      <th>57</th>\n      <td>1.008913</td>\n    </tr>\n    <tr>\n      <th>58</th>\n      <td>1.017788</td>\n    </tr>\n    <tr>\n      <th>59</th>\n      <td>1.004746</td>\n    </tr>\n  </tbody>\n</table>\n<p>242 rows × 1 columns</p>\n</div>"
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dtrader_return"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-26T12:30:16.996189200Z",
     "start_time": "2024-02-26T12:30:16.953160800Z"
    }
   },
   "id": "bb9ba42101ef8d29",
   "execution_count": 4
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "df_return=pd.DataFrame()\n",
    "dtrader_return=dtrader_return/dtrader_return.shift(1)\n",
    "dtrader_return.fillna(1,inplace=True)\n",
    "df_return['daily_return']=dtrader_return['daily_return']-1"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-26T12:30:17.018968800Z",
     "start_time": "2024-02-26T12:30:16.987134700Z"
    }
   },
   "id": "63217f5e03ea2653",
   "execution_count": 5
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "data": {
      "text/plain": "\"\\ndf_return=pd.DataFrame()\\ndtrader=np.load('alphastock/code/RL/res/best_test_cr_whole.npy')\\ndtrader=dtrader.reshape(248)\\ndtrader=pd.DataFrame(dtrader)\\ndtrader.columns=['daily_return']\\ndtrader_return=dtrader/dtrader.shift(1)\\ndtrader_return.fillna(1,inplace=True)\\ndf_return['daily_return']=dtrader_return['daily_return']-1\\n\""
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "df_return=pd.DataFrame()\n",
    "dtrader=np.load('alphastock/code/RL/res/best_test_cr_whole.npy')\n",
    "dtrader=dtrader.reshape(248)\n",
    "dtrader=pd.DataFrame(dtrader)\n",
    "dtrader.columns=['daily_return']\n",
    "dtrader_return=dtrader/dtrader.shift(1)\n",
    "dtrader_return.fillna(1,inplace=True)\n",
    "df_return['daily_return']=dtrader_return['daily_return']-1\n",
    "'''"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-26T12:30:17.086115Z",
     "start_time": "2024-02-26T12:30:16.999190300Z"
    }
   },
   "id": "404ff71b7f7304c7",
   "execution_count": 6
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\胡逸凡\\AppData\\Local\\Temp\\ipykernel_4832\\3311902912.py:21: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  df_trade.rename(columns={'close_r' : 'daily_return'}, inplace=True)\n",
      "C:\\Users\\胡逸凡\\AppData\\Local\\Temp\\ipykernel_4832\\3311902912.py:22: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  df_trade['daily_return'] = df_trade['daily_return'] - 1\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "#大盘和日收益率\n",
    "path='TRA/data/splab.pkl'\n",
    "f=open(path,'rb')\n",
    "index_df=pickle.load(f)\n",
    "index_df = index_df.reset_index()\n",
    "# index_df.rename(columns={'label':'daily_return', 'dt':'datetime'},inplace=True)\n",
    "index_df.rename(columns={'label':'daily_return', 'Date':'datetime'},inplace=True)\n",
    "index_df=index_df[index_df['datetime']>'2022-12-31']\n",
    "index_df.reset_index(inplace=True,drop=True)\n",
    "index_df = index_df.groupby('datetime')['daily_return'].mean().reset_index()\n",
    "index_date_unique=index_df['datetime'].unique()\n",
    "'''\n",
    "csitrade=pd.read_csv('E:/baselines/day_level_dataset/ccso.csv')\n",
    "csitrade['close_r']=csitrade['close']/csitrade['close'].shift(1)\n",
    "csitrade.reset_index(inplace=True,drop=True)\n",
    "df_trade=csitrade\n",
    "df_trade.rename(columns={'kdcode':'instrument','dt':'datetime'},inplace=True)\n",
    "df_trade['datetime'] = df_trade['datetime'].astype('datetime64[ns]')\n",
    "df_trade=df_trade[df_trade['datetime']>'2023-01-01']\n",
    "df_trade.rename(columns={'close_r' : 'daily_return'}, inplace=True)\n",
    "df_trade['daily_return'] = df_trade['daily_return'] - 1\n",
    "index_df = df_trade.groupby('datetime')['daily_return'].mean().reset_index()"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-26T12:30:17.143843900Z",
     "start_time": "2024-02-26T12:30:17.016908400Z"
    }
   },
   "id": "5f03bb78b42c7916",
   "execution_count": 7
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "portfolio_df_performance = df_return\n",
    "index_df_performance = index_df.set_index(['datetime'])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-26T12:30:17.157929500Z",
     "start_time": "2024-02-26T12:30:17.142427Z"
    }
   },
   "id": "b40c4e0b45e8a372",
   "execution_count": 8
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "# ARR = (portfolio_df_performance['daily_return']+1).cumprod()\n",
    "# ARR.to_csv(\"alphastock.csv\", index=None)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-26T12:30:17.188389900Z",
     "start_time": "2024-02-26T12:30:17.159019100Z"
    }
   },
   "id": "8b2bc78340fb13dc",
   "execution_count": 9
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "data": {
      "text/plain": "    daily_return\n0   0.000000e+00\n1  -1.110223e-16\n2   1.363703e-02\n3  -1.603888e-02\n4   2.450352e-03\n..           ...\n55  6.097642e-04\n56 -4.335360e-03\n57  1.108752e-02\n58  8.796324e-03\n59 -1.281376e-02\n\n[242 rows x 1 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>daily_return</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>0.000000e+00</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>-1.110223e-16</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>1.363703e-02</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>-1.603888e-02</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>2.450352e-03</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>55</th>\n      <td>6.097642e-04</td>\n    </tr>\n    <tr>\n      <th>56</th>\n      <td>-4.335360e-03</td>\n    </tr>\n    <tr>\n      <th>57</th>\n      <td>1.108752e-02</td>\n    </tr>\n    <tr>\n      <th>58</th>\n      <td>8.796324e-03</td>\n    </tr>\n    <tr>\n      <th>59</th>\n      <td>-1.281376e-02</td>\n    </tr>\n  </tbody>\n</table>\n<p>242 rows × 1 columns</p>\n</div>"
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "portfolio_df_performance"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-26T12:30:17.225041700Z",
     "start_time": "2024-02-26T12:30:17.173883Z"
    }
   },
   "id": "d06487f246885ea7",
   "execution_count": 10
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "data": {
      "text/plain": "            daily_return\ndatetime                \n2023-01-03      0.012240\n2023-01-04     -0.000450\n2023-01-05      0.007891\n2023-01-06      0.001752\n2023-01-09      0.003574\n...                  ...\n2023-12-25      0.000425\n2023-12-26     -0.007765\n2023-12-27      0.004482\n2023-12-28      0.018146\n2023-12-29      0.003977\n\n[242 rows x 1 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>daily_return</th>\n    </tr>\n    <tr>\n      <th>datetime</th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2023-01-03</th>\n      <td>0.012240</td>\n    </tr>\n    <tr>\n      <th>2023-01-04</th>\n      <td>-0.000450</td>\n    </tr>\n    <tr>\n      <th>2023-01-05</th>\n      <td>0.007891</td>\n    </tr>\n    <tr>\n      <th>2023-01-06</th>\n      <td>0.001752</td>\n    </tr>\n    <tr>\n      <th>2023-01-09</th>\n      <td>0.003574</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>2023-12-25</th>\n      <td>0.000425</td>\n    </tr>\n    <tr>\n      <th>2023-12-26</th>\n      <td>-0.007765</td>\n    </tr>\n    <tr>\n      <th>2023-12-27</th>\n      <td>0.004482</td>\n    </tr>\n    <tr>\n      <th>2023-12-28</th>\n      <td>0.018146</td>\n    </tr>\n    <tr>\n      <th>2023-12-29</th>\n      <td>0.003977</td>\n    </tr>\n  </tbody>\n</table>\n<p>242 rows × 1 columns</p>\n</div>"
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "index_df_performance"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-26T12:30:17.295204200Z",
     "start_time": "2024-02-26T12:30:17.204231700Z"
    }
   },
   "id": "37f6f54ecdcc3221",
   "execution_count": 11
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\胡逸凡\\AppData\\Local\\Temp\\ipykernel_4832\\4043393616.py:20: FutureWarning: 'm' is deprecated and will be removed in a future version, please use 'ME' instead.\n",
      "  monthly_statistics_df = alpha_df_performance[net_value_columns].resample('m').last()\n",
      "C:\\Users\\胡逸凡\\AppData\\Local\\Temp\\ipykernel_4832\\4043393616.py:25: FutureWarning: The default fill_method='pad' in DataFrame.pct_change is deprecated and will be removed in a future version. Either fill in any non-leading NA values prior to calling pct_change or specify 'fill_method=None' to not fill NA values.\n",
      "  monthly_statistics_df = monthly_statistics_df.pct_change()\n",
      "C:\\Users\\胡逸凡\\AppData\\Local\\Temp\\ipykernel_4832\\4043393616.py:29: FutureWarning: 'y' is deprecated and will be removed in a future version, please use 'YE' instead.\n",
      "  yearly_statistics_df = alpha_df_performance[net_value_columns].resample('y').last()\n",
      "C:\\Users\\胡逸凡\\AppData\\Local\\Temp\\ipykernel_4832\\4043393616.py:34: FutureWarning: The default fill_method='pad' in DataFrame.pct_change is deprecated and will be removed in a future version. Either fill in any non-leading NA values prior to calling pct_change or specify 'fill_method=None' to not fill NA values.\n",
      "  yearly_statistics_df = yearly_statistics_df.pct_change()\n",
      "C:\\Users\\胡逸凡\\AppData\\Roaming\\Python\\Python310\\site-packages\\numpy\\core\\fromnumeric.py:3643: FutureWarning: The behavior of DataFrame.std with axis=None is deprecated, in a future version this will reduce over both axes and return a scalar. To retain the old behavior, pass axis=0 (or do not pass axis)\n",
      "  return std(axis=axis, dtype=dtype, out=out, ddof=ddof, **kwargs)\n",
      "C:\\Users\\胡逸凡\\AppData\\Roaming\\Python\\Python310\\site-packages\\numpy\\core\\fromnumeric.py:3643: FutureWarning: The behavior of DataFrame.std with axis=None is deprecated, in a future version this will reduce over both axes and return a scalar. To retain the old behavior, pass axis=0 (or do not pass axis)\n",
      "  return std(axis=axis, dtype=dtype, out=out, ddof=ddof, **kwargs)\n",
      "C:\\Users\\胡逸凡\\AppData\\Roaming\\Python\\Python310\\site-packages\\numpy\\core\\fromnumeric.py:3643: FutureWarning: The behavior of DataFrame.std with axis=None is deprecated, in a future version this will reduce over both axes and return a scalar. To retain the old behavior, pass axis=0 (or do not pass axis)\n",
      "  return std(axis=axis, dtype=dtype, out=out, ddof=ddof, **kwargs)\n"
     ]
    }
   ],
   "source": [
    "alpha_df_performance = pd.DataFrame()\n",
    "alpha_df_performance['portfolio_daily_return'] = portfolio_df_performance['daily_return']\n",
    "alpha_df_performance['index_daily_return'] = index_df_performance['daily_return']\n",
    "alpha_df_performance['alpha_daily_return'] = alpha_df_performance['portfolio_daily_return'] - \\\n",
    "                                                alpha_df_performance['index_daily_return']\n",
    "alpha_df_performance['portfolio_net_value'] = (alpha_df_performance['portfolio_daily_return'] + 1).cumprod()\n",
    "alpha_df_performance['index_net_value'] = (\n",
    "        alpha_df_performance['index_daily_return'] + 1).cumprod()\n",
    "alpha_df_performance['alpha_net_value'] = (alpha_df_performance['alpha_daily_return'] + 1).cumprod()\n",
    "\n",
    "net_value_columns = ['portfolio_net_value',\n",
    "                        'index_net_value',\n",
    "                        'alpha_net_value']\n",
    "\n",
    "alpha_statistics_df = pd.DataFrame(index=alpha_df_performance[net_value_columns].columns,\n",
    "                                    columns=[\"年化收益\", \"年化波动率\", \"最大回撤率\", \"夏普率\", \"Calmar\", \"IR\", \"月度胜率\"])\n",
    "\n",
    "# alpha_df_performance.set_index(\"dt\", inplace=True)\n",
    "alpha_df_performance.index = pd.to_datetime(alpha_df_performance.index)\n",
    "monthly_statistics_df = alpha_df_performance[net_value_columns].resample('m').last()\n",
    "monthly_statistics_df = pd.concat([alpha_df_performance[:1][\n",
    "                                        ['portfolio_net_value',\n",
    "                                        'index_net_value', 'alpha_net_value']],\n",
    "                                    monthly_statistics_df])\n",
    "monthly_statistics_df = monthly_statistics_df.pct_change()\n",
    "monthly_statistics_df = monthly_statistics_df.dropna()\n",
    "monthly_statistics_df.index = monthly_statistics_df.index.date\n",
    "## TODO 补充第一年的数据\n",
    "yearly_statistics_df = alpha_df_performance[net_value_columns].resample('y').last()\n",
    "yearly_statistics_df = pd.concat([alpha_df_performance[:1][\n",
    "                                        ['portfolio_net_value',\n",
    "                                        'index_net_value', 'alpha_net_value']],\n",
    "                                    yearly_statistics_df])\n",
    "yearly_statistics_df = yearly_statistics_df.pct_change()\n",
    "yearly_statistics_df = yearly_statistics_df.dropna()\n",
    "yearly_statistics_df.index = yearly_statistics_df.index.date\n",
    "\n",
    "alpha_statistics_df.loc[:, \"年化收益\"] = np.mean(\n",
    "    (alpha_df_performance[net_value_columns].tail(1)) ** (252 / len(alpha_df_performance)) - 1)\n",
    "alpha_statistics_df.loc[:, \"年化波动率\"] = np.std(\n",
    "    alpha_df_performance[net_value_columns] / alpha_df_performance[net_value_columns].shift(1) - 1) * np.sqrt(\n",
    "    252)\n",
    "alpha_statistics_df.loc[:, \"累积收益\"] = np.mean(alpha_df_performance[net_value_columns].tail(1) - 1)\n",
    "alpha_statistics_df.loc[:, \"累积波动率\"] = np.std(\n",
    "    alpha_df_performance[net_value_columns] / alpha_df_performance[net_value_columns].shift(1) - 1)\n",
    "alpha_statistics_df.loc[:, \"最大回撤率\"] = np.min(\n",
    "    (alpha_df_performance[net_value_columns] - alpha_df_performance[net_value_columns].cummax()) /\n",
    "    alpha_df_performance[net_value_columns].cummax())\n",
    "alpha_statistics_df.loc[:, \"夏普率\"] = alpha_statistics_df[\"年化收益\"] / alpha_statistics_df[\"年化波动率\"]\n",
    "alpha_statistics_df.loc[:, \"Calmar\"] = alpha_statistics_df[\"年化收益\"] / abs(alpha_statistics_df[\"最大回撤率\"])\n",
    "alpha_statistics_df.loc[:, \"IR\"] = np.mean(\n",
    "    alpha_df_performance[net_value_columns] / alpha_df_performance[net_value_columns].shift(1) - 1) * np.sqrt(\n",
    "    252) / np.std(alpha_df_performance[net_value_columns] / alpha_df_performance[net_value_columns].shift(1) - 1)\n",
    "alpha_statistics_df.loc[:, \"月度胜率\"] = monthly_statistics_df[\n",
    "                                            monthly_statistics_df > 0].count() / monthly_statistics_df.count()"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-26T12:30:17.333508100Z",
     "start_time": "2024-02-26T12:30:17.244925900Z"
    }
   },
   "id": "ce1dc4786748ff52",
   "execution_count": 12
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "data": {
      "text/plain": "                         年化收益    年化波动率     最大回撤率       夏普率    Calmar       IR  \\\nportfolio_net_value  0.004943  0.16387 -0.040244  0.030161  0.122814  0.11212   \nindex_net_value      0.004943      NaN -0.040244       NaN  0.122814      NaN   \nalpha_net_value      0.004943      NaN -0.040244       NaN  0.122814      NaN   \n\n                    月度胜率      累积收益     累积波动率  \nportfolio_net_value  NaN  0.004746  0.010323  \nindex_net_value      NaN  0.004746       NaN  \nalpha_net_value      NaN  0.004746       NaN  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>年化收益</th>\n      <th>年化波动率</th>\n      <th>最大回撤率</th>\n      <th>夏普率</th>\n      <th>Calmar</th>\n      <th>IR</th>\n      <th>月度胜率</th>\n      <th>累积收益</th>\n      <th>累积波动率</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>portfolio_net_value</th>\n      <td>0.004943</td>\n      <td>0.16387</td>\n      <td>-0.040244</td>\n      <td>0.030161</td>\n      <td>0.122814</td>\n      <td>0.11212</td>\n      <td>NaN</td>\n      <td>0.004746</td>\n      <td>0.010323</td>\n    </tr>\n    <tr>\n      <th>index_net_value</th>\n      <td>0.004943</td>\n      <td>NaN</td>\n      <td>-0.040244</td>\n      <td>NaN</td>\n      <td>0.122814</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>0.004746</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>alpha_net_value</th>\n      <td>0.004943</td>\n      <td>NaN</td>\n      <td>-0.040244</td>\n      <td>NaN</td>\n      <td>0.122814</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>0.004746</td>\n      <td>NaN</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "alpha_statistics_df"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-26T12:30:17.334529100Z",
     "start_time": "2024-02-26T12:30:17.297292900Z"
    }
   },
   "id": "40d9319a749cebd4",
   "execution_count": 13
  },
  {
   "cell_type": "markdown",
   "source": [
    "alpha stock \n",
    "\n",
    "ASR = ARR / AVol;   CR = ARR / abs(MDD)\n",
    "        ARR    AVol    MDD    ASR    CR    IR\n",
    "hs300 -0.164  0.153  -0.245 -1.072 -0.669 -1.098\n",
    "\n",
    "zz500 -0.017  0.148  -0.166 -0.115 -0.102 -0.043\n",
    "\n",
    "sp500  0.122  0.140  -0.126  0.871  0.968  0.892\n",
    "   \n",
    "nas100 0.372  0.178  -0.134  1.781  2.776  1.869"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "af550dda07e31c6"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
